/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sys.screen;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.sql.SQLException;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import sys.bean.ClienteBean;
import sys.bean.ContasReceberBean;
import sys.bean.MotivoBloqueioBean;
import sys.bean.PedidoBean;
import sys.dao.ClienteDao;
import sys.dao.ContasReceberDao;
import sys.dao.MotivoBloqueioDao;
import sys.dao.PedidoDao;
import sys.dao.ValeMercadoriaDao;
import sys.utils.LetterUpper;
import sys.utils.Mensagens;
import sys.utils.Singleton;
import sys.utils.Utils;
import static sys.utils.Utils.codCorreto;
import static sys.utils.Utils.dataCorreta;
import static sys.utils.Utils.diasAtraso;
import static sys.utils.Utils.numParaCalculos;

/**
 *
 * @author Administrador
 */
public class UIRelatorioClientes extends javax.swing.JFrame {

    SimpleDateFormat formDataSpac = new SimpleDateFormat("yyyyMMdd");
    SimpleDateFormat formDataBr = new SimpleDateFormat("dd/MM/yyyy");
    NumberFormat formatoMoeda = NumberFormat.getCurrencyInstance();
    ClienteBean cliente;
    MotivoBloqueioBean motivoBloqueio;

    double mediaAtraso = 0;
    double gTotalVencido = 0;
    double gTotalVencer = 0;
    double gTotalHaver = 0;

    public UIRelatorioClientes() {
        initComponents();
        setExtendedState(MAXIMIZED_BOTH);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        eventoTeclaEspecial();
        jpTabela.setVisible(false);
    }

    private void eventoTeclaEspecial() {
        getRootPane().getInputMap(JPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0, true), "FUNCAO_F12");
        getRootPane().getActionMap().put("FUNCAO_F12", new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                loadSearch();
            }
        });
    }

    /*
     metodo chamado quando mouse ou tecla passa na tabela.
     Soma o que tem na tabela e exibe o valor
     */
    private void somaTabela() {
        double soma = 0;
        int[] linhas = tabelaContas.getSelectedRows();
        for (int i = 0; i < linhas.length; i++) {
            soma += Double.parseDouble(numParaCalculos(tabelaContas.getValueAt(linhas[i], 5).toString()));
        }
        lbSoma.setText("SOMA " + formatoMoeda.format(soma));
    }

    /*
     retornando primeiro dia do mês referente a 6 meses atras
     */
    public Date dataSeisMesesAtras() {
        Date data;

        Date dataTemp = Utils.subtrairDias(new Date(), 180);
        data = Utils.stringToDate(Utils.retornaData(dataTemp, 0, 1));

        return data;
    }

    public void limpaCampos() {
        txNomeCliente.setText("");
        txDataCadastroCliente.setText("");
        txEndereco.setText("");
        txRG.setText("");
        txCPF.setText("");
        txDataCadastroCliente.setText("");
        txQtdCompras.setText("");
        txTotalPendente.setText("");
        txTotalHaver.setText("");
        txMediaAtraso.setText("");
        txPgtosVale.setText("");
        txTotalGastos.setText("");
        txFone.setText("");
        txFoneTrabalho.setText("");
        txFoneConjuge.setText("");
        lbRenda.setText("");
        lbSituacao.setText("");
        txObs.setText("");
        DefaultTableModel modelo = (DefaultTableModel) tabelaContas.getModel();
        modelo.setNumRows(0);
        jpGrafTotaisCliente.removeAll();
        jpGrafTotaisCliente.repaint();
        jpGrafUltimosMeses.removeAll();
        jpGrafUltimosMeses.repaint();
        lbSoma.setText("");

    }

    public void geraRelatorio() {
        if (txCodigo.getText().equals("")) {
            loadSearch();
        } else {
            final BarraProgresso pb = new BarraProgresso(this);
            SwingWorker worker = new SwingWorker() {

                @Override
                protected Object doInBackground() throws Exception {
                    pb.gerarJanela();

                    jpTabela.setVisible(true);

                    pb.lbDescricao.setText("CARREGANDO DADOS, AGUARDE...");
                    preencheCampos();

                    pb.lbDescricao.setText("GERANDO GRAFICO, AGUARDE...");
                    grafTotaisCliente();

                    pb.lbDescricao.setText("GERANDO GRAFICO, AGUARDE...");
                    ultimosGastosCliente();

                    pb.lbDescricao.setText("GERANDO , AGUARDE...");
                    atTabelaContas();

                    return null;
                }

                @Override
                protected void done() {
                    pb.fechar();
                }
            };
            worker.execute();
        }
    }

    public String formatoMoeda(double valor) {
        return formatoMoeda.format(valor).replace("R$", "");
    }

    private String flagConsulta() {
        return "P','A";
    }

    private void loadSearch() {
        UIPesquisaCliente uipc = new UIPesquisaCliente(this, true);
        uipc.setVisible(true);
    }

    private void atTabelaContas() {
        int cont = 0;
        mediaAtraso = 0;

        DefaultTableModel modelo = (DefaultTableModel) tabelaContas.getModel();
        modelo.setNumRows(0);
        try {

            for (ContasReceberBean cRece : ContasReceberDao.listaContasCliente(txCodigo.getText(), flagConsulta())) {
                if (cRece.getFlagSituacao().equals("PAGO")) {
                    mediaAtraso += diasAtraso(cRece.getDataVencimento(), cRece.getDataPagamento());
                    cont++;
                    modelo.addRow(new Object[]{
                        cRece.getnDocumento(), dataCorreta(cRece.getDataVencimento()), dataCorreta(cRece.getDataPagamento()), diasAtraso(cRece.getDataVencimento(), cRece.getDataPagamento()),
                        cRece.getFlagSituacao(), formatoMoeda(cRece.getVrParcela()), formatoMoeda(cRece.getVrPago())
                    });

                } else {
                    //verificando se tem recebimento parcial
                    if (!cRece.getnRecebimento().equals("")) {
                        modelo.addRow(new Object[]{
                            cRece.getnDocumento(), dataCorreta(cRece.getDataVencimento()), "", diasAtraso(cRece.getDataVencimento(), formDataSpac.format(new Date())) + " - P. PARCIAL",
                            cRece.getFlagSituacao(), formatoMoeda(cRece.getVrParcela() - cRece.getVrPago())
                        });
                    } else {
                        modelo.addRow(new Object[]{
                            cRece.getnDocumento(), dataCorreta(cRece.getDataVencimento()), "", diasAtraso(cRece.getDataVencimento(), formDataSpac.format(new Date())),
                            cRece.getFlagSituacao(), formatoMoeda(cRece.getVrParcela()), ""
                        });
                    }
                }
            }

            if ((mediaAtraso / cont) > 15) {
                txMediaAtraso.setText(formatoMoeda(mediaAtraso / cont) + " DIAS");
                txMediaAtraso.setForeground(new java.awt.Color(255, 0, 102));
            } else {
                txMediaAtraso.setText(formatoMoeda(mediaAtraso / cont) + " DIAS");
                txMediaAtraso.setForeground(new java.awt.Color(51, 51, 255));
            }

            tabelaContas.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

                    //Alinhando o conteudo das linhas no centro
                    setHorizontalAlignment(SwingConstants.CENTER);

                    String dataVencimento = table.getValueAt(row, 1).toString();
                    String flagPgto = table.getValueAt(row, 4).toString();

                    Date data = new Date();
                    Date dataBanco = Utils.stringToDate(dataVencimento);

                    if (data.after(dataBanco) && flagPgto.equals("PENDENTE")) {
                        setForeground(Color.red);
                    } else {
                        setForeground(null);
                    }
                    return this;
                }
            });

        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro\n" + ex.getMessage());
        }
    }

    public void preencheCampos() {
        try {
            /*
             dados que preenchem o panel superior
             */
            cliente = ClienteDao.consultaCliente(codCorreto(txCodigo.getText(), 5));
            txCodigo.setText(cliente.getCodigo());
            txNomeCliente.setText(cliente.getNome());
            txEndereco.setText(cliente.getEndereco() + " " + cliente.getnEndereco() + " - " + cliente.getBairro() + " - " + cliente.getDescCidade() + " (" + cliente.getEstado() + ")");
            txDataCadastroCliente.setText(cliente.getDataCadastro());
            txQtdCompras.setText(cliente.getQtdCompra() + "");
            txFone.setText(cliente.getFone());
            txFoneTrabalho.setText(cliente.getFoneTrabalho());
            txFoneConjuge.setText(cliente.getFoneCJ());
            lbRenda.setText(formatoMoeda.format(cliente.getRenda()));
            txPgtosVale.setText(formatoMoeda(ContasReceberDao.pgtosEmVale(txCodigo.getText())));

            if (cliente.getSituacao().equals("B")) {
                motivoBloqueio = MotivoBloqueioDao.consultaMotivoBloqueio(codCorreto(txCodigo.getText(), 5));
                lbSituacao.setText("CLIENTE BLOQUEADO - MOTIVO: " + motivoBloqueio.getCodigo() + "-" + motivoBloqueio.getDescricao());
                lbSituacao.setForeground(new java.awt.Color(255, 0, 102));

            } else {
                lbSituacao.setText("SITUAÇÃO DO CLIENTE - ATIVO");
                lbSituacao.setForeground(new java.awt.Color(51, 51, 255));
            }

            if (cliente.getObs() != null) {
                txObs.setText("OBSERVAÇÃO:\t" + cliente.getObs());
            }

            /*
             dados para preencher todos os dados do cliente
             */
            if (cliente.getTipo().equals("F")) {
                lbRazao.setText("NOME:");
                lbCPFCNPJ.setText("CPF:");
                lbRGIE.setText("RG:");
                txCPF.setText(cliente.getCpfCnpj());
                txRG.setText(cliente.getRgIe());

                txFoneTrabalho.setEnabled(true);
                txFoneConjuge.setEnabled(true);
                lbFoneConjuge.setEnabled(true);
                lbFoneTrabalho.setEnabled(true);
            } else {
                lbRazao.setText("RAZÃO SOCIAL:");
                lbCPFCNPJ.setText("CNPJ:");
                lbRGIE.setText("INS. ESTADUAL:");
                txCPF.setText(cliente.getCpfCnpj());
                txRG.setText(cliente.getRgIe());

                txFoneTrabalho.setEnabled(false);
                txFoneConjuge.setEnabled(false);
                lbFoneConjuge.setEnabled(false);
                lbFoneTrabalho.setEnabled(false);
            }
        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao carregar dados do cliente\n" + ex.getMessage());
        }
    }

    /*
     * Gerando o gráfico totais cliente (pizza)
     *
     */
    private void grafTotaisCliente() {
        DefaultPieDataset cds = cdtTotaisCliente();

        //String titulo = "TOTAL TRANSAÇÕES CLIENTE";
        String titulo = "";
        JFreeChart graf = ChartFactory.createPieChart3D(titulo, cds, false, true, false);

        PiePlot3D plot = (PiePlot3D) graf.getPlot();
        plot.setForegroundAlpha(0.7f);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {1}"));

        ChartPanel myChartpanel = new ChartPanel(graf, true);
        myChartpanel.setSize(jpGrafTotaisCliente.getWidth(), jpGrafTotaisCliente.getHeight());
        myChartpanel.setVisible(true);
        jpGrafTotaisCliente.removeAll();
        jpGrafTotaisCliente.add(myChartpanel);
        jpGrafTotaisCliente.revalidate();
        jpGrafTotaisCliente.repaint();
    }
    /*
     * gerando grafico de totais do cliente (pizza)
     *
     */

    private DefaultPieDataset cdtTotaisCliente() {
        DefaultPieDataset pieDataset = new DefaultPieDataset();

        try {

            double totalPendente = ContasReceberDao.totalCliente(txCodigo.getText(), "A");
            double totalPago = ContasReceberDao.totalCliente(txCodigo.getText(), "P");

            double totalVencer = ContasReceberDao.totalCliente(txCodigo.getText(), formDataSpac.format(new Date()), "A' AND C12DTVEN >");
            double totalVencido = ContasReceberDao.totalCliente(txCodigo.getText(), formDataSpac.format(new Date()), "A' AND C12DTVEN <");

            if (totalPendente > 0) {
                pieDataset.setValue("TOTAL PENDENTE", totalPendente);
            }
            if (totalPago > 0) {
                pieDataset.setValue("TOTAL PAGO", totalPago);
            }
            if (totalVencer > 0) {
                pieDataset.setValue("TOTAL A VENCER", totalVencer);
            }
            if (totalVencido > 0) {
                pieDataset.setValue("TOTAL VENCIDO", totalVencido);
            }

            double haver = ValeMercadoriaDao.totalHaverCliente(txCodigo.getText());

            txTotalPendente.setText(formatoMoeda.format(totalPendente));

            if (haver > 0) {
                txTotalHaver.setForeground(new java.awt.Color(255, 0, 102));

            } else {
                txTotalHaver.setForeground(new java.awt.Color(51, 51, 255));
            }

            if ((totalPendente - haver) < 0) {
                txSaldo.setForeground(new java.awt.Color(255, 0, 102));
            } else {
                txSaldo.setForeground(new java.awt.Color(51, 51, 255));
            }

            txTotalHaver.setText(formatoMoeda.format(haver));
            txSaldo.setText(formatoMoeda.format(totalPendente - haver));
            txTotalGastos.setText(formatoMoeda.format(totalPago + totalPendente - Double.parseDouble((Utils.numParaCalculos(txPgtosVale.getText())))));

        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("Erro\n" + ex.getMessage());
        }
        return pieDataset;
    }

    /*
     * Gerando o grafico de gastos do cliente nos ultimos meses (Linha)
     *
     */
    private void ultimosGastosCliente() {

        DefaultCategoryDataset cds = cdtUltimosGastos();
        //data, primeiro ou ultimo dia, formato spac ou brasil de data
//        String titulo = "GASTOS NOS ULTIMOS MESES";
        String titulo = "";
        String eixoy = "";
        String txt_legenda = "";
        boolean legenda = false;
        boolean tooltips = false;
        boolean urls = false;

        JFreeChart grafico = ChartFactory.createLineChart(titulo, txt_legenda, eixoy, cds, PlotOrientation.VERTICAL, legenda, tooltips, urls);

        CategoryPlot plot = (CategoryPlot) grafico.getCategoryPlot();
        CategoryItemRenderer itemRerender = plot.getRenderer();

        // itemRerender.setSeriesPaint(0, java.awt.Color.GREEN);
        itemRerender.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getCurrencyInstance()));
        itemRerender.setItemLabelsVisible(true);

        ChartPanel mychChartPanel = new ChartPanel(grafico, true);
        mychChartPanel.setSize(jpGrafUltimosMeses.getWidth(), jpGrafUltimosMeses.getHeight());
        mychChartPanel.setVisible(true);
        jpGrafUltimosMeses.removeAll();
        jpGrafUltimosMeses.add(mychChartPanel);
        jpGrafUltimosMeses.revalidate();
        jpGrafUltimosMeses.repaint();
    }

    /*
     * Gerando o grafico de gastos do cliente nos ultimos meses (Linha)
     */
    private DefaultCategoryDataset cdtUltimosGastos() {
        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        try {
            /*
             Parametros do metodo grafVendaAnual: data, primeiro ou ultimo dia, formato spac ou brasil de data
             */
            List<PedidoBean> listaGastos = PedidoDao.gastosClientePeriodo(txCodigo.getText(), formDataSpac.format(dataSeisMesesAtras()), formDataSpac.format(new Date()));
            for (PedidoBean p : listaGastos) {
                if (p.getData().equals("01") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "JANEIRO");
                }
                if (p.getData().equals("02") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "FEVEREIRO");
                }
                if (p.getData().equals("03") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "MARÇO");
                }
                if (p.getData().equals("04") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "ABRIL");
                }
                if (p.getData().equals("05") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "MAIO");
                }
                if (p.getData().equals("06") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "JUNHO");
                }
                if (p.getData().equals("07") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "JULHO");
                }
                if (p.getData().equals("08") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "AGOSTO");
                }
                if (p.getData().equals("09") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "SETEMBRO");
                }
                if (p.getData().equals("10") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "OUTUBRO");
                }
                if (p.getData().equals("11") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "NOVEMBRO");
                }
                if (p.getData().equals("12") && p.getvTotal() > 0) {
                    dataSet.addValue(p.getvTotal(), "", "DEZEMBRO");
                }
            }

        } catch (SQLException | IOException e) {
            Mensagens.msgErro("erro\n" + e.getMessage());
        }
        return dataSet;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jpGrafTotaisCliente = new javax.swing.JPanel();
        jpGrafUltimosMeses = new javax.swing.JPanel();
        jpTabela = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tabelaContas = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jpDados1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txCodigo = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        txNomeCliente = new javax.swing.JTextField();
        txEndereco = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        lbRazao = new javax.swing.JLabel();
        lbRGIE = new javax.swing.JLabel();
        txRG = new javax.swing.JTextField();
        lbCPFCNPJ = new javax.swing.JLabel();
        txCPF = new javax.swing.JTextField();
        txDataCadastroCliente = new javax.swing.JTextField();
        txQtdCompras = new javax.swing.JTextField();
        lbCPFCNPJ1 = new javax.swing.JLabel();
        lbCPFCNPJ2 = new javax.swing.JLabel();
        jpDados2 = new javax.swing.JPanel();
        lbTotal7 = new javax.swing.JLabel();
        txSaldo = new javax.swing.JTextField();
        lbTotal3 = new javax.swing.JLabel();
        lbTotal2 = new javax.swing.JLabel();
        txTotalHaver = new javax.swing.JTextField();
        txTotalGastos = new javax.swing.JTextField();
        txTotalPendente = new javax.swing.JTextField();
        lbTotal1 = new javax.swing.JLabel();
        lbTotal8 = new javax.swing.JLabel();
        txMediaAtraso = new javax.swing.JTextField();
        lbTotal9 = new javax.swing.JLabel();
        txPgtosVale = new javax.swing.JTextField();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        txObs = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        lbRenda = new javax.swing.JLabel();
        lbSituacao = new javax.swing.JLabel();
        lbSoma = new javax.swing.JLabel();
        jPanel13 = new javax.swing.JPanel();
        lbRGIE1 = new javax.swing.JLabel();
        txFone = new javax.swing.JTextField();
        lbFoneTrabalho = new javax.swing.JLabel();
        txFoneTrabalho = new javax.swing.JTextField();
        lbFoneConjuge = new javax.swing.JLabel();
        txFoneConjuge = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ANÁLISE DE CLIENTES");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jpGrafTotaisCliente.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jpGrafTotaisClienteLayout = new javax.swing.GroupLayout(jpGrafTotaisCliente);
        jpGrafTotaisCliente.setLayout(jpGrafTotaisClienteLayout);
        jpGrafTotaisClienteLayout.setHorizontalGroup(
            jpGrafTotaisClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jpGrafTotaisClienteLayout.setVerticalGroup(
            jpGrafTotaisClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jpGrafUltimosMeses.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jpGrafUltimosMesesLayout = new javax.swing.GroupLayout(jpGrafUltimosMeses);
        jpGrafUltimosMeses.setLayout(jpGrafUltimosMesesLayout);
        jpGrafUltimosMesesLayout.setHorizontalGroup(
            jpGrafUltimosMesesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jpGrafUltimosMesesLayout.setVerticalGroup(
            jpGrafUltimosMesesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        tabelaContas.setAutoCreateRowSorter(true);
        tabelaContas.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        tabelaContas.setForeground(new java.awt.Color(51, 51, 255));
        tabelaContas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "NR. DOC.", "VENCIMENTO", "PAGAMENTO", "ATR./ANT.", "SITUACAO", "VALOR", "VALOR PAGO"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaContas.setGridColor(new java.awt.Color(204, 204, 204));
        tabelaContas.getTableHeader().setReorderingAllowed(false);
        tabelaContas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaContasMouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tabelaContasMouseReleased(evt);
            }
        });
        jScrollPane3.setViewportView(tabelaContas);

        javax.swing.GroupLayout jpTabelaLayout = new javax.swing.GroupLayout(jpTabela);
        jpTabela.setLayout(jpTabelaLayout);
        jpTabelaLayout.setHorizontalGroup(
            jpTabelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
        );
        jpTabelaLayout.setVerticalGroup(
            jpTabelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpTabelaLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpGrafTotaisCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpGrafUltimosMeses, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpTabela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jpTabela, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jpGrafTotaisCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jpGrafUltimosMeses, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        jpDados1.setBackground(new java.awt.Color(255, 255, 255));
        jpDados1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DADOS DO CLIENTE:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jLabel4.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel4.setText("CODIGO:");

        txNomeCliente.setDocument(new LetterUpper());
        txCodigo.setBackground(new java.awt.Color(245, 245, 245));
        txCodigo.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txCodigo.setForeground(new java.awt.Color(51, 51, 255));
        txCodigo.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txCodigo.setBorder(null);
        txCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txCodigoActionPerformed(evt);
            }
        });
        txCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txCodigoKeyReleased(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find-2.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        txNomeCliente.setDocument(new LetterUpper());
        txNomeCliente.setEditable(false);
        txNomeCliente.setBackground(new java.awt.Color(245, 245, 245));
        txNomeCliente.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txNomeCliente.setForeground(new java.awt.Color(51, 51, 255));
        txNomeCliente.setBorder(null);

        txEndereco.setDocument(new LetterUpper());
        txEndereco.setEditable(false);
        txEndereco.setBackground(new java.awt.Color(245, 245, 245));
        txEndereco.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txEndereco.setForeground(new java.awt.Color(51, 51, 255));
        txEndereco.setBorder(null);

        jLabel5.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel5.setText("ENDEREÇO:");

        lbRazao.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbRazao.setText("NOME:");

        lbRGIE.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbRGIE.setText("RG:");

        txNomeCliente.setDocument(new LetterUpper());
        txRG.setEditable(false);
        txRG.setBackground(new java.awt.Color(245, 245, 245));
        txRG.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txRG.setForeground(new java.awt.Color(51, 51, 255));
        txRG.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txRG.setBorder(null);

        lbCPFCNPJ.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbCPFCNPJ.setText("CPF:");

        txNomeCliente.setDocument(new LetterUpper());
        txCPF.setEditable(false);
        txCPF.setBackground(new java.awt.Color(245, 245, 245));
        txCPF.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txCPF.setForeground(new java.awt.Color(51, 51, 255));
        txCPF.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txCPF.setBorder(null);

        txEndereco.setDocument(new LetterUpper());
        txDataCadastroCliente.setEditable(false);
        txDataCadastroCliente.setBackground(new java.awt.Color(245, 245, 245));
        txDataCadastroCliente.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txDataCadastroCliente.setForeground(new java.awt.Color(51, 51, 255));
        txDataCadastroCliente.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txDataCadastroCliente.setBorder(null);

        txQtdCompras.setEditable(false);
        txQtdCompras.setBackground(new java.awt.Color(245, 245, 245));
        txQtdCompras.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txQtdCompras.setForeground(new java.awt.Color(51, 51, 255));
        txQtdCompras.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txQtdCompras.setBorder(null);

        lbCPFCNPJ1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbCPFCNPJ1.setText("CLIENTE DESDE:");

        lbCPFCNPJ2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbCPFCNPJ2.setText("QTD. COMPRAS:");

        javax.swing.GroupLayout jpDados1Layout = new javax.swing.GroupLayout(jpDados1);
        jpDados1.setLayout(jpDados1Layout);
        jpDados1Layout.setHorizontalGroup(
            jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDados1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpDados1Layout.createSequentialGroup()
                        .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpDados1Layout.createSequentialGroup()
                                .addComponent(txCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpDados1Layout.createSequentialGroup()
                                .addComponent(lbRazao)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 274, Short.MAX_VALUE))
                            .addComponent(txNomeCliente)))
                    .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txEndereco, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addGroup(jpDados1Layout.createSequentialGroup()
                                .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txRG, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lbRGIE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbCPFCNPJ)
                                    .addComponent(txCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbCPFCNPJ1)
                                    .addComponent(txDataCadastroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(lbCPFCNPJ2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(txQtdCompras))))))
                .addContainerGap())
        );
        jpDados1Layout.setVerticalGroup(
            jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDados1Layout.createSequentialGroup()
                .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbRazao))
                .addGap(1, 1, 1)
                .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txNomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(txEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpDados1Layout.createSequentialGroup()
                        .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbCPFCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbRGIE, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(1, 1, 1)
                        .addGroup(jpDados1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txRG, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jpDados1Layout.createSequentialGroup()
                        .addComponent(lbCPFCNPJ1, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)
                        .addComponent(txDataCadastroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpDados1Layout.createSequentialGroup()
                        .addComponent(lbCPFCNPJ2, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)
                        .addComponent(txQtdCompras, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpDados2.setBackground(new java.awt.Color(255, 255, 255));
        jpDados2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "TOTALIZADORES DO CLIENTE:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        lbTotal7.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbTotal7.setText("MÉDIA ATRASO:");

        txSaldo.setEditable(false);
        txSaldo.setBackground(new java.awt.Color(245, 245, 245));
        txSaldo.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
        txSaldo.setForeground(new java.awt.Color(51, 51, 255));
        txSaldo.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txSaldo.setBorder(null);

        lbTotal3.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbTotal3.setText("SALDO:");

        lbTotal2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbTotal2.setText("HAVER:");

        txTotalHaver.setEditable(false);
        txTotalHaver.setBackground(new java.awt.Color(245, 245, 245));
        txTotalHaver.setFont(new java.awt.Font("Calibri", 1, 13)); // NOI18N
        txTotalHaver.setForeground(new java.awt.Color(255, 0, 102));
        txTotalHaver.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTotalHaver.setBorder(null);

        txTotalGastos.setEditable(false);
        txTotalGastos.setBackground(new java.awt.Color(245, 245, 245));
        txTotalGastos.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
        txTotalGastos.setForeground(new java.awt.Color(51, 51, 255));
        txTotalGastos.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTotalGastos.setBorder(null);

        txTotalPendente.setEditable(false);
        txTotalPendente.setBackground(new java.awt.Color(245, 245, 245));
        txTotalPendente.setFont(new java.awt.Font("Calibri", 1, 13)); // NOI18N
        txTotalPendente.setForeground(new java.awt.Color(51, 51, 255));
        txTotalPendente.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTotalPendente.setBorder(null);

        lbTotal1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbTotal1.setText("PENDENTE:");

        lbTotal8.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbTotal8.setText("TOTAL DE GASTOS");

        txMediaAtraso.setEditable(false);
        txMediaAtraso.setBackground(new java.awt.Color(245, 245, 245));
        txMediaAtraso.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txMediaAtraso.setForeground(new java.awt.Color(51, 51, 255));
        txMediaAtraso.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txMediaAtraso.setBorder(null);

        lbTotal9.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbTotal9.setText("PGTOS. EM VALE:");

        txPgtosVale.setEditable(false);
        txPgtosVale.setBackground(new java.awt.Color(245, 245, 245));
        txPgtosVale.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txPgtosVale.setForeground(new java.awt.Color(51, 51, 255));
        txPgtosVale.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txPgtosVale.setBorder(null);

        javax.swing.GroupLayout jpDados2Layout = new javax.swing.GroupLayout(jpDados2);
        jpDados2.setLayout(jpDados2Layout);
        jpDados2Layout.setHorizontalGroup(
            jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDados2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbTotal1)
                    .addComponent(lbTotal2)
                    .addGroup(jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txTotalPendente, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lbTotal3, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txTotalHaver, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txSaldo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbTotal7)
                    .addComponent(txMediaAtraso, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbTotal8)
                    .addComponent(txTotalGastos, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbTotal9)
                    .addComponent(txPgtosVale, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jpDados2Layout.setVerticalGroup(
            jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDados2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpDados2Layout.createSequentialGroup()
                        .addComponent(lbTotal1)
                        .addGap(1, 1, 1)
                        .addComponent(txTotalPendente, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jpDados2Layout.createSequentialGroup()
                            .addComponent(lbTotal7)
                            .addGap(24, 24, 24))
                        .addComponent(txMediaAtraso, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpDados2Layout.createSequentialGroup()
                        .addComponent(lbTotal2)
                        .addGap(1, 1, 1)
                        .addComponent(txTotalHaver, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jpDados2Layout.createSequentialGroup()
                            .addComponent(lbTotal9)
                            .addGap(24, 24, 24))
                        .addComponent(txPgtosVale, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDados2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDados2Layout.createSequentialGroup()
                        .addComponent(lbTotal3)
                        .addGap(1, 1, 1)
                        .addComponent(txSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDados2Layout.createSequentialGroup()
                        .addComponent(lbTotal8)
                        .addGap(1, 1, 1)
                        .addComponent(txTotalGastos, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel11.setBackground(new java.awt.Color(255, 255, 255));
        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "SITUAÇÃO DO CLIENTE/OBSERVAÇÕES:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        txObs.setEditable(false);
        txObs.setColumns(20);
        txObs.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        txObs.setForeground(new java.awt.Color(204, 0, 255));
        txObs.setLineWrap(true);
        txObs.setRows(5);
        jScrollPane4.setViewportView(txObs);

        jLabel1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel1.setText("RENDA MENSAL:");

        lbRenda.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        lbRenda.setForeground(new java.awt.Color(0, 51, 255));

        lbSituacao.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        lbSoma.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        lbSoma.setForeground(new java.awt.Color(204, 51, 255));
        lbSoma.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbSituacao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbRenda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbSoma, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel11Layout.createSequentialGroup()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbRenda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbSoma, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbSituacao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel13.setBackground(new java.awt.Color(255, 255, 255));
        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "CONTATOS DO CLIENTE:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        lbRGIE1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbRGIE1.setText("FONE:");

        txNomeCliente.setDocument(new LetterUpper());
        txFone.setEditable(false);
        txFone.setBackground(new java.awt.Color(245, 245, 245));
        txFone.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txFone.setForeground(new java.awt.Color(51, 51, 255));
        txFone.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txFone.setBorder(null);

        lbFoneTrabalho.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbFoneTrabalho.setText("FONE TRABALHO:");

        txNomeCliente.setDocument(new LetterUpper());
        txFoneTrabalho.setEditable(false);
        txFoneTrabalho.setBackground(new java.awt.Color(245, 245, 245));
        txFoneTrabalho.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txFoneTrabalho.setForeground(new java.awt.Color(51, 51, 255));
        txFoneTrabalho.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txFoneTrabalho.setBorder(null);

        lbFoneConjuge.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbFoneConjuge.setText("FONE CÔNJUGE:");

        txNomeCliente.setDocument(new LetterUpper());
        txFoneConjuge.setEditable(false);
        txFoneConjuge.setBackground(new java.awt.Color(245, 245, 245));
        txFoneConjuge.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        txFoneConjuge.setForeground(new java.awt.Color(51, 51, 255));
        txFoneConjuge.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txFoneConjuge.setBorder(null);

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txFone)
                    .addComponent(txFoneTrabalho)
                    .addGroup(jPanel13Layout.createSequentialGroup()
                        .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbRGIE1)
                            .addComponent(lbFoneTrabalho)
                            .addComponent(lbFoneConjuge))
                        .addGap(0, 78, Short.MAX_VALUE))
                    .addComponent(txFoneConjuge, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addComponent(lbRGIE1)
                .addGap(1, 1, 1)
                .addComponent(txFone, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbFoneTrabalho, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(txFoneTrabalho, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbFoneConjuge, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txFoneConjuge, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpDados1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpDados2, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jpDados2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpDados1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txCodigoActionPerformed
        geraRelatorio();
    }//GEN-LAST:event_txCodigoActionPerformed

    private void txCodigoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txCodigoKeyReleased
        if (txCodigo.getText().equals("")) {
            limpaCampos();
        }
    }//GEN-LAST:event_txCodigoKeyReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        loadSearch();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        UITelaPrincipal telaPrincipal = new UITelaPrincipal();
        telaPrincipal.carregaPermissoesUsuario(Singleton.getCodigo());
        telaPrincipal.setVisible(true);
    }//GEN-LAST:event_formWindowClosing

    private void tabelaContasMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaContasMouseReleased
        somaTabela();
    }//GEN-LAST:event_tabelaContasMouseReleased

    private void tabelaContasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaContasMouseClicked
        somaTabela();
    }//GEN-LAST:event_tabelaContasMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JPanel jpDados1;
    private javax.swing.JPanel jpDados2;
    private javax.swing.JPanel jpGrafTotaisCliente;
    private javax.swing.JPanel jpGrafUltimosMeses;
    private javax.swing.JPanel jpTabela;
    private javax.swing.JLabel lbCPFCNPJ;
    private javax.swing.JLabel lbCPFCNPJ1;
    private javax.swing.JLabel lbCPFCNPJ2;
    private javax.swing.JLabel lbFoneConjuge;
    private javax.swing.JLabel lbFoneTrabalho;
    private javax.swing.JLabel lbRGIE;
    private javax.swing.JLabel lbRGIE1;
    private javax.swing.JLabel lbRazao;
    private javax.swing.JLabel lbRenda;
    private javax.swing.JLabel lbSituacao;
    private javax.swing.JLabel lbSoma;
    private javax.swing.JLabel lbTotal1;
    private javax.swing.JLabel lbTotal2;
    private javax.swing.JLabel lbTotal3;
    private javax.swing.JLabel lbTotal7;
    private javax.swing.JLabel lbTotal8;
    private javax.swing.JLabel lbTotal9;
    private javax.swing.JTable tabelaContas;
    public javax.swing.JTextField txCPF;
    public javax.swing.JTextField txCodigo;
    private javax.swing.JTextField txDataCadastroCliente;
    private javax.swing.JTextField txEndereco;
    public javax.swing.JTextField txFone;
    public javax.swing.JTextField txFoneConjuge;
    public javax.swing.JTextField txFoneTrabalho;
    private javax.swing.JTextField txMediaAtraso;
    private javax.swing.JTextField txNomeCliente;
    private javax.swing.JTextArea txObs;
    private javax.swing.JTextField txPgtosVale;
    private javax.swing.JTextField txQtdCompras;
    public javax.swing.JTextField txRG;
    private javax.swing.JTextField txSaldo;
    private javax.swing.JTextField txTotalGastos;
    private javax.swing.JTextField txTotalHaver;
    private javax.swing.JTextField txTotalPendente;
    // End of variables declaration//GEN-END:variables
}
